<?php
/**
 * @title 1185. 一周中的第几天 - 数学
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }

class Solution {

    /**
     * @param Integer $day
     * @param Integer $month
     * @param Integer $year
     * @return String
     */
    function dayOfTheWeek($day, $month, $year) {
        /**
         * @since 2022-01-06 每个月天数
         */
        $monthArray = [
            1 => 31,
            2 => 28,
            3 => 31,
            4 => 30,
            5 => 31,
            6 => 30,
            7 => 31,
            8 => 31,
            9 => 30,
            10 => 31,
            11 => 30,
            12 => 31,
        ];

        /**
         * @since 2022-01-06 是否闰年
         * @since 2022-01-06 4的倍数，但不是100的倍数。400的倍数
         */
        if($year != 2100 AND $year % 4 == 0){
            $monthArray[2] = 29;
        } else {}

        /**
         * @since 2022-01-06 1971-1-1, 星期五
         * @since 2022-01-06 计算年的天数
         */
        $addYear = $year-1971;
        $day += $addYear*365;
        // echo "addYear = ", $day, PHP_EOL;

        /**
         * @since 2022-01-06 闰年, 1972
         */
        $day += intval(($addYear+2)/4);
        // echo "闰年, ", $day, PHP_EOL;

        /**
         * @since 2022-01-06 算算天数
         */
        for($m=1; $m<$month; $m++){
            $day += $monthArray[$m];
        }
        // echo "最终，", $day, PHP_EOL;

        /**
         * @since 2022-01-06 取模
         */
        $day = $day % 7;
        // echo "取模，", $day, PHP_EOL;

        /**
         * @since 2022-01-06 1971-1-1, 星期五
         */
        $weekArray = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday",];

        /**
         * @return
         */
        return $weekArray[$day];
    }
}

/**
 * @url http://127.0.0.1/leetcode/202201/2022.01.03.php
 */
$datas = [
    [31, 8, 2019], // 6
    [18, 7, 1999], // 7
    [15, 8, 1993], // 7
    [31, 8, 2100], // 4
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    if(count($data) <= 20){
        var_dump($data);
    } else {
        var_dump(count($data));
    }

    $obj = new Solution();
    $result = $obj->dayOfTheWeek(...$data);
    // $result = $obj->($xhprof->tree($data));
    // $result = $obj->($xhprof->listNode($data));
    // $result = $obj->find(...$data);
    var_dump($result);
    // if(count($result)<=20){
    //     var_dump($result);
    // } else {
    //     var_dump(count($result));
    // }
    echo str_repeat(PHP_EOL, 3);
    echo str_repeat("<br>", 3);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
